package Java实训.第二天JDK8特性;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

public class Num1 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < 20; i++) {
            list.add(random.nextInt(10));
        }
        System.out.println("整体集合为: " + list);
        AtomicInteger count1 = new AtomicInteger();
        AtomicInteger count2 = new AtomicInteger();
        list.stream().filter(s -> s % 2 == 0).forEach(s -> count1.addAndGet(s));
        System.out.println("偶数和为: " + count1);
        list.stream().filter(s -> s % 2 != 0).forEach(s -> count2.addAndGet(s));
        System.out.println("奇数和为: " + count2);
    }

}
